/*
 * SharedPtr.cpp
 *
 *  Created on: 2012/02/26
 *      Author: naoki
 */

#include "StdAfx.h"
#include "NTEngine/Base/Impl/SharedPtrImpl.h"

namespace NTEngine {

SharedCount::~SharedCount() {
	if ( mImpl ) {
		mImpl->unref();
		if ( mImpl->count() <= 0 ) {
			delete mImpl;
		}
		mImpl = 0;
	}
}

SharedCount::SharedCount( const SharedCount& a ) : mImpl( a.mImpl ) {
	if ( mImpl ) {
		mImpl->refer();
	}
}

void SharedCount::operator=( const SharedCount& a ) {
	if ( mImpl ) {
		mImpl->unref();
		if ( mImpl->count() <= 0 ) {
			delete mImpl;
		}
	}
	mImpl = a.mImpl;
	if ( mImpl ) {
		mImpl->refer();
	}
}

} // namespace NTEngine
